import 'package:flutter/material.dart';
import 'package:flutter_eve_plugin/utils/color_common.dart';
import 'package:flutter_eve_plugin/utils/screen_util.dart';

class RankUserIcon extends StatelessWidget {
  final String iconUrl;
  final int level;
  final double width;
  final double height;

  RankUserIcon(
      {this.iconUrl = '', this.level = 0, this.width = 40, this.height = 40});

  _isShowLevel() {
    bool isShowLevel = level != null;
    if (isShowLevel) {
      return Container(
        width: setRatio(60),
        child: Center(
          child: Text(
            'LV.$level',
            style: TextStyle(
                color: Color(0xFFEFF5FD),
                fontSize: 9,
                fontWeight: FontWeight.bold),
          ),
        ),
        decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(15.0),
            gradient: LinearGradient(
                begin: Alignment.topCenter,
                end: Alignment.bottomCenter,
                colors: <Color>[
                  Color(ColorRes.colorEF9237),
                  Color(ColorRes.colorF7D14B),
                ])),
      );
    } else {
      return Container();
    }
  }

  @override
  Widget build(BuildContext context) {
    return Stack(
      overflow: Overflow.visible,
      children: <Widget>[
        Container(
          width: setRatio(width),
          height: setRatio(height),
          decoration: BoxDecoration(
            shape: BoxShape.circle,
            color: Colors.white,
            image: DecorationImage(
              image: NetworkImage(iconUrl.isEmpty
                  ? "http://oupsfzeja.bkt.clouddn.com/4d292464-5b2b-40ad-b61c-3b84978371ddimage/png"
                  : iconUrl),
            ),
          ),
        ),
        Positioned(bottom: -3, width: setRatio(width), child: _isShowLevel())
      ],
    );
  }
}
